package com.sjl.web;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sjl.entity.Teachers;
import com.sjl.service.TeachersService;
import com.sjl.util.MyId;
import com.sjl.util.Result;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author sjl
 * @since 2020-11-01
 */
@RestController
@RequestMapping("/teachers")
public class TeachersController {

	@Resource
	private TeachersService teachersServiceSjl;

	@RequestMapping("/selectTeachersSjl")
	public Object selectTeachersSjl(Teachers teachers, Page<Teachers> page) {
		return teachersServiceSjl.selectByPage(page, teachers);
	}

	@RequestMapping("createTeachersSjl")
	public Object createTeachersSjl(Teachers Teachers) {
		Teachers.setTeachersCardNo(MyId.getTeachersCardNo());
		boolean i = teachersServiceSjl.save(Teachers);
		if (i == true) {
			return new Result(0, "添加成功");
		}
		return new Result(1, "添加失败");
	}

	@RequestMapping("updateTeachersSjl")
	public Object updateTeachers(Teachers Teachers) {
		boolean bl = teachersServiceSjl.updateById(Teachers);
		if (bl == true) {
			return new Result(0, "修改成功！");
		}
		return new Result(1, "修改失败！");
	}

	@RequestMapping("deleteTeachersSjl")
	public Object deleteTeachersSjl(Integer teachersId) {

		System.out.println("1111===>" + teachersId);
		boolean bl = teachersServiceSjl.removeById(teachersId);
		if (bl) {
			return new Result(0, "删除成功！");
		}
		return new Result(1, "删除失败！");
	}
}
